package com.ruoyi.forApp.controller;

import com.ruoyi.forApp.domain.TableForApp;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.system.course.domain.CourseArrange;
import com.ruoyi.project.system.course.service.ICourseArrangeService;
import com.ruoyi.project.system.course.service.ICourseService;
import com.ruoyi.project.system.dept.domain.Dept;
import com.ruoyi.project.system.dept.service.IDeptService;
import com.ruoyi.project.system.user.domain.User;
import com.ruoyi.project.system.user.service.IUserService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.List;

@Controller
public class TableControllerForApp {
    @Autowired
    private ICourseArrangeService courseArrangeService;

    @Autowired
    private IUserService userService;
    @Autowired
    private IDeptService deptService;

    @PostMapping("/getCourseTable")
    @ResponseBody
    public List<TableForApp> list(Long userId)
    {
        User user=userService.selectUserById(userId);
        Dept dept=deptService.selectDeptById(user.getDeptId());
        CourseArrange courseArrange=new CourseArrange();
        courseArrange.setDeptId(dept.getDeptId());
        List<CourseArrange> list = courseArrangeService.selectCourseArrangeList(courseArrange);
        List<TableForApp> tableList=new ArrayList<>();
        for (CourseArrange courseArrange1:list){
            TableForApp tableForApp=new TableForApp();
            tableForApp.setCourseId(courseArrange1.getCourseId());
            tableForApp.setCourseName(courseArrange1.getCourse().getCourseName());
            tableForApp.setWeekDay(courseArrange1.getWeekDay());
            tableForApp.setStartTime(courseArrange1.getStartTime());
            tableForApp.setEndTime(courseArrange1.getEndTime());
            tableForApp.setPlace(courseArrange1.getPlace());
            if (courseArrange1.getTeacherId()==null){
                tableForApp.setTeacherId(null);
                tableForApp.setTeacherName("未安排");
            }else {
                tableForApp.setTeacherId(courseArrange1.getTeacherId());
                tableForApp.setTeacherName(courseArrange1.getUser().getUserName());
            }
            tableList.add(tableForApp);
        }
        return tableList;
    }



}
